<%@tag description="page index" pageEncoding="UTF-8"%>
<%@ attribute name="recordCount" type="java.lang.Integer" required="true"%>
<%@ attribute name="pageSize" type="java.lang.Integer" required="true"%>

<%
Integer o = (Integer)jspContext.getAttribute("recordCount");
int recordCount = o.intValue();

o = (Integer)jspContext.getAttribute("pageSize");
int pageSize = o.intValue();


int pageCount = recordCount / pageSize;
if (pageCount * pageSize < recordCount) ++pageCount;
%>

<%
String uri = request.getRequestURI();
String query = request.getQueryString();
String url = "";
String pt = "pg=[0-9]+";

int currentPage = 1;
String search=request.getParameter("search");
String subje = request.getParameter("subje");
String title=request.getParameter("title");
	if (request.getParameter("pg") != null) {
	   	 currentPage = Integer.parseInt(request.getParameter("pg"));
	   	 url = uri + "?" + query;
		} else {
	   	 if (query == null) url = uri + "?pg=1";
	    	else url = uri + "?" + query + "&pg=1";
		}



if (currentPage > pageCount) currentPage = pageCount;
int base = ((currentPage - 1) / 10) * 10;
%>
<STYLE TYPE="text/css">
form{
	display:inline-block;
}
  a.pager {  margin-left:5px; margin-right:5px;display:inline-block; text-decoration: none; color: #A000FF;font-size:17px; 
             }
  b.pager {  text-decoration:underline; margin-left:5px; margin-right:5px;display:inline-block; font-size:17px;  }
</STYLE>

<% if (base > 0) { %>
<form action="index.jsp" method="post">
	<%if(search!=null && search!="") {%> 
	<input type="hidden" name="search" value=<%=search%>>
	<%} %>
	
	<%if(subje!=null && subje!="") {%> 

	<input type="hidden" name="subje" value=<%=subje%>>
	<%} %>
<input type="hidden" name="title" value=<%=title%>>
<input type="hidden" name="pg" value=<%=base%>>
    <button class="btn" type="submit">◀이전</button>
    </form>
<% } %>

<% for (int i=1; i<=10; ++i) { %>
  <% int n = base + i; %>
  <% if (n > pageCount) break; %>
  <% if (n == currentPage) { %>
  <button class="btn">
      <b><u><%=currentPage%></u></b>
      </button>
  <% } else { %>
  <form action="index.jsp" method="post">
  
  	<%if(search!=null && search!="") {%> 
	<input type="hidden" name="search" value=<%=search%>>
	<%} %>
	
	<%if(subje!=null && subje!="") {%> 

	<input type="hidden" name="subje" value=<%=subje%>>
	<%} %>
<input type="hidden" name="title" value=<%=title%>>
<input type="hidden" name="pg" value=<%=n%>>
   <button class=btn><%=n%></button>
    </form>
  
  <% } %>
<% } %>


<% if (base+11 <= pageCount) { %>
<form action="index.jsp" method="post">
<%if(search!=null && search!="") {%> 
<input type="hidden" name="search" value=<%=search%>>
<%} %>
<%if(search!=null && search!="") {%> 
<input type="hidden" name="subje" value=<%=subje%>>
<%} %>
<input type="hidden" name="title" value=<%=title%>>
<input type="hidden" name="pg" value=<%= base+11%>>
    <button class="btn" type="submit">다음▶</button>
    </form>
 <%} %>

<%if(search != ""&&search!=null || subje!=null && subje!="" && !subje.equals("0")){%>
<form id="search" action="index.jsp" method="post">
	<button class="btn" id="btn" type="submit">검색취소</button>
</form>
<%} %>	



